<title>系统更新</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>系统更新</cite></a>
    </div>
</div>
<div class="layui-col-xs12 layui-col-sm8 layui-col-md8 layui-col-md-offset2 layui-col-sm-offset2">
    <div class="layui-field-box">
        <div class="layui-card">
            <div class="layui-card-header">检查更新</div>
            <div class="layui-card-body" id="updatebody">
                <script type="text/html" template lay-url="ajax.php" lay-type="post" lay-data="{act:'update'}">
                    {{# if(d.code == 1){ }}
                    {{d.msg}}
                    {{d.button}}
                    {{d.log}}
                    {{#  } else if(d.code == 0) { }}
                    {{d.msg}}
                    {{# } else { }}
                    <div class="layui-bg-red" style="text-indent:2em;">啊哦，更新服务器开小差了，请刷新此页面。</div>
                    {{# } }}
                </script>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['admin', 'layer'], function () {
        var $ = layui.$,
            admin = layui.admin,
            layer = layui.layer;

        var active = {
            updatebutton: function () {
                layer.msg('更新过程比较久请耐心等待不要刷新网页否则会导致更新失败！', {
                    icon: 7,
                    time: 3000,
                }, function () {
                    var array = {};
                    array['act'] = 'update';
                    array['do'] = true;
                    admin.req({
                        url: 'ajax.php',
                        type: 'post',
                        data: array,
                        timeout: 0,
                        load: 'layer.msg("正在更新，不要刷新网页否则会导致更新失败！", {icon: 16,shade: 0.01,time: 0});',
                        success: function (json) {
                            if (json.code === 1) {
                                $('#updatebody').html(json.msg);
                            } else if (json.code === 0) {
                                layer.msg(json.msg, {
                                    icon: 1
                                });
                            } else {
                                layer.msg('啊哦，更新服务器开小差了，请重试！', {
                                    icon: 2
                                });
                            }
                        }
                    });
                });
            }
        }
        $(document).on('click', '.button-click', function () {
            var othis = $(this),
                type = othis.data('type');
            active[type] ? active[type].call(this, othis) : '';
        });
    });
</script>